using System;
using System.Collections;
using System.Text;

using LibrErian.Interfaces.Services;
using LibrErian.Model;
using Microsoft.Practices.CompositeUI;

namespace LibrErian.Services
{
    [Service(typeof(IBookService))]
    public class BookService : ServiceBase, IBookService
    {
        private Library currentLibrary;

        public IList GetBooks()
        {
            return DataManager.GetBooks(currentLibrary.Id);
        }

        public IList GetBooksByGenre(int genreId)
        {
            return DataManager.GetBooksByGenre(currentLibrary.Id, genreId);
        }

        public IList GetBooksByAuthor(int authorId)
        {
            return DataManager.GetBooksByAuthor(currentLibrary.Id, authorId);
        }

        public void SetCurrentLibrary(Library library)
        {
            currentLibrary = library;
        }

        public void Save(Book bookToSave)
        {
            if (bookToSave.Library == null)
            {
                bookToSave.Library = currentLibrary;
            }

            DataManager.SaveOrUpdate(bookToSave);
        }
    }
}
